function r2 = model_r2_mean_1D_v2(para,t,parameter)
% para(1): nu
% para(2): delta^2
% output: roughness square
N=(1:20000)';
% freq=5;
% w=1.0;
% L=8000; %nm

if(size(t,1)==1)
    t = t';
end

freq = parameter(1);
A = parameter(2);
L = parameter(3);

c2 = para(1);
sigma2 = para(2)*para(1);

W=zeros(2,size(N,1));
W(1,freq)=A*sqrt(L/2);
k=sigma2./(2*(-4*c2.*repmat(N,1,length(t)).^2*pi*pi/L/L));
lambda=-4*c2.*N.^2*pi*pi/L/L;

a2=k.*(exp(2.*lambda*t')-1);
r2=2*sum(a2,1)/(L)+(W(1,freq)*(exp(lambda(freq,1)*t')-1)/lambda(freq,1)).^2;
r2=r2';
end

% function r2 = model_r2(para,t)
% % para(1): nu
% % para(2): delta^2
% % output: roughness square
% N=(1:100)';
% 
% % para2=150*2*pi*para(1)/sum((1./[1:100]).^2);
% para(2)=150*2*pi*para(1)/sum((1./[1:100]).^2);
% k=para2./(2*para(1).*repmat(N,1,length(t)).^2);
% lambda=para(1).*N.^2;
% a2=k.*(1-exp(-2.*lambda*t));
% r2=2*sum(a2,1)/(2*pi);
% 
% end



% function r2 = model_r2(para,t)
% % para(1): nu
% % para(2): delta^2
% % output: roughness square
% N=(1:100)';
% k=para(2)./(2*para(1).*repmat(N,1,length(t)).^2);
% lambda=para(1).*N.^2;
% a2=k.*(1-exp(-2.*lambda*t));
% r2=2*sum(a2,1)/(2*pi);
% end





% function r2 = model_r2(para,t)
% % para(1): nu
% % para(2): delta^2
% % output: roughness square
% 
% N=(1:100)';
% 
% para2=-23*8000/2/sum(-1./(2*4*para(1).*N.^2*pi*pi/8000/8000));
% % para(2)=150*2*pi*para(1)/sum((1./[1:100]).^2);
% k=para2./(2*(-4*para(1).*repmat(N,1,length(t)).^2*pi*pi/8000/8000));
% lambda=-4*para(1).*N.^2*pi*pi/8000/8000;
% a2=k.*(exp(2.*lambda*t)-1);
% r2=2*sum(a2,1)/(8000);
% 
% 
% 
% end